package com.example.spring.boot.gson.utils;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.internal.GsonBuildConfig;

import java.util.Objects;

/**
 * <p>
 * GsonUtil
 * </p>
 *
 * @author weixin
 * @date 2023/3/27 23:21
 */
public class GsonUtil {

    public static String formatJson(Object object) {
        if (Objects.equals(object, null)){
            return "null";
        }
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.setPrettyPrinting();
        Gson gson = gsonBuilder.create();
        String jsonStr = gson.toJson(object);
        return jsonStr;
    }

}
